<?php

	class Option_model extends CI_Model
	{
	    var $table;
	    
	    function __construct()
	    {
	        parent::__construct();
	        $this->table = $this->db->dbprefix('sys_option');
	    }
		function editOption($key,$value)
		{    	        
    	    $query = $this->getOption($key);
 	    
    	    if($query->num_rows>0)
    	    {
    	        
    	        $updateSql = "update `{$this->table}` set `value`='{$value}' where `key`='{$key}'";
    	    }
    	    else
    	    {
    	        $updateSql = "INSERT INTO  `{$this->table}` (`key` ,`value`)VALUES ('$key',  '$value');";
    	    }
    	    //var_dump($updateSql);
    	    $this->db->query($updateSql);
		}
		
    	function getOption($key)
        {
            return $query = $this->db->get_where($this->table, array('key' => $key));
        }
        
        function getOptions()
        {
        	return $this->db->get($this->table);
        }
	}